<template>
    <div>
        <el-form ref="student">
            <!-- 添加 -->

            <div style="width:800px">
                <el-form-item label="添加大类">
                    <el-input v-model="class_name"></el-input>
                </el-form-item>

                <el-form-item style="width:970px">
                    <el-button type="primary" @click="addClass(class_name)">添加</el-button>
                </el-form-item>
            </div>

            <div style="width:800px">
                <el-form-item label="添加小类">
                    <el-input v-model="category_name"></el-input>
                </el-form-item>
                <el-form-item label="所属大类的id">
                    <el-input v-model="class_id"></el-input>
                </el-form-item>
                <el-form-item style="width:970px">
                    <el-button type="primary" @click="addLittleClass(category_name, class_id)">添加</el-button>
                </el-form-item>
            </div>
        </el-form>
    </div>
</template>
<script>
export default {
    data() {
        return {
            class_name: '',
            category_name: '',
            class_id: '',
            category_id: '',
            student:[]
        };
    },
    methods: {
        addClass: function(class_name) {
            console.log('aaaaaaaaaaaa');
            var that = this;

            console.log('iiiiiiiiiiiiiiiiii');
            this.axios({
                method: 'post',
                url: 'http://localhost:8080/s/addGoodsClass',
                //修改了提交的数据类型为json格式
                headers: { 'Content-Type': 'application/json;charset=utf-8' },
                data: JSON.stringify({
                    class_name
                })
            })
                .then(res => {
                    console.log(res.data);
                })
                .catch(error => {
                    console.log(error);
                });
        },
        addLittleClass: function(category_name, class_id) {
            console.log('aaaaaaaaaaaa');
            var that = this;

            console.log('xxxxxxxxxxx');
            this.axios({
                method: 'post',
                url: 'http://localhost:8080/s/addGoodsCategory',
                //修改了提交的数据类型为json格式
                headers: { 'Content-Type': 'application/json;charset=utf-8' },
                data: JSON.stringify({
                    category_name,
                    class_id
                })
            })
                .then(res => {
                    console.log(res.data);
                })
                .catch(error => {
                    console.log(error);
                });
        },
    }
};
</script>
<style scoped></style>
